#include <stdio.h>

void swap(int* x, int* y) {
	int temp;
	temp = *y;
	*y = *x;
	*x = temp;
}

void bubble(int arr[], int n) {
	int i;
	int j;
	for (i = 0; i < n; ++i) {
		for (j = i; j < n - i - 1; ++j) {
			if (arr[j] > arr[j+1]) {
				swap(&arr[j], &arr[j+1]);	
			}
		}	
	}
}

void print(int arr[], int n) {
	int i;
	for (i = 0; i < n; ++i) {
		printf("%d ", arr[i]);
	}
	printf("\n");
}

int main() {
	int arr[5] = {3, 6, 15, 4, 8};
	printf("Before: ");
	print(arr, 5);
	
	bubble(arr, 5);

	printf("After: ");
	print(arr, 5);

	return 0;
}
